import com.sun.jmx.remote.internal.ArrayQueue;
import 计时器.MyTimer;
import 阻塞队列.MyArrayBlockingQueue;

import java.util.ArrayDeque;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.*;

public class Test {
    private double i;
    private double j;


    public void setI(double i) {
        this.i = i;
    }


    public void setJ(double j) {
        this.j = j;
    }

    //直角坐标系
    public static Test RighTest(double x,double y){
        Test test=new Test();
        test.setI(x);
        test.setJ(y);
        return test;
    }
    //极坐标系
    public static Test PolarTest(double a,double b){
        Test test=new Test();
        test.setI(a);
        test.setJ(b);
        return test;
    }

    public static void main(String[] args) {
        ExecutorService pool=Executors.newCachedThreadPool();
        pool.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println("任务1");
            }
        });
        pool.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println("任务2");
            }
        });

    }
    public static void main10(String[] args) throws InterruptedException {

        Thread thread=new Thread(()->{
            while (!Thread.currentThread().isInterrupted()){
                System.out.println("Hello Thread");
            }
        });
        thread.start();
        //休息一会
        Thread.sleep(1000);
        //设置标志位 为true
        thread.interrupt();
    }

    public static boolean isFlag=false;
    public static void main9(String[] args) throws InterruptedException {
        Thread thread=new Thread(()->{
            while (!isFlag){
                System.out.println("Hello Thread");
            }
        });
        thread.start();
        //休息一会
        Thread.sleep(1000);
        //设置标志位
        isFlag=true;

    }
    public static void main8(String[] args) throws InterruptedException {
        //创建一个扫描线程
        MyTimer myTimer=new MyTimer();
        //主线程
        myTimer.schedule(new Runnable() {
            @Override
            public void run() {
                System.out.println("时间1");
            }
        },1000);
        myTimer.schedule(new Runnable() {
            @Override
            public void run() {
                System.out.println("时间2");
            }
        },2000);
        myTimer.schedule(new Runnable() {
            @Override
            public void run() {
                System.out.println("时间3");
            }
        },3000);

    }
    public static void main7(String[] args) {
        Timer timer=new Timer();
        Thread thread=new Thread(()->{
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    System.out.println("时间1");
                }
            },5000);
        });
        thread.start();

        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("时间2");
            }
        },2000);


    }
    public static void main1(String[] args) throws InterruptedException {
        MyArrayBlockingQueue myArrayBlockingQueue=new MyArrayBlockingQueue();
        Thread thread1=new Thread(()->{
            myArrayBlockingQueue.put(10);
        });

        Thread thread2=new Thread(()->{
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(myArrayBlockingQueue.take());
        });


        Thread thread3=new Thread(()->{
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(myArrayBlockingQueue.take());
        });

        thread1.start();
        thread2.start();
        thread3.start();

        thread1.join();
        thread2.join();
        thread3.join();

    }
    public static void main3(String[] args) {
        MyArrayBlockingQueue myArrayBlockingQueue=new MyArrayBlockingQueue();
        myArrayBlockingQueue.put(1);
        myArrayBlockingQueue.put(3);
        myArrayBlockingQueue.put(5);
        System.out.println(myArrayBlockingQueue.take());
        System.out.println(myArrayBlockingQueue.take());
        System.out.println(myArrayBlockingQueue.take());
    }
    public static void main2(String[] args) {
        BlockingDeque<Integer> blockingDeque= new LinkedBlockingDeque<>(10);
        BlockingQueue<Integer>blockingQueue1=new ArrayBlockingQueue<>(10);

    }
    public static void main6(String[] args) {
        Timer timer=new Timer();
        timer.schedule(new TimerTask(){
            @Override
            public void run() {
                System.out.println("开始计时1 ");
            }
        },1000);

        timer.schedule(new TimerTask(){
            @Override
            public void run() {
                System.out.println("开始计时2 ");
            }
        },2000);
        timer.schedule(new TimerTask(){
            @Override
            public void run() {
                System.out.println("开始计时3 ");
            }
        },3000);

        System.out.println("开始计时！");
    }
}
